package com.itheima.d1_exception_javac;

public class demo4 {
    public static void main(String[] args)  {
        try {
            checkAge(-34);
        } catch (IllegalAgeException e) {
            e.printStackTrace();
        }
    }

    private static void checkAge(int age) throws IllegalAgeException {
        if(age<0 || age>200){
            //throws:在方法声明上的，抛出方法内部的异常
            //throw：在方法内部直接创建一个异常的对象
            throw new IllegalAgeException(age+" is illegal");//注意和throws的区别
        }
        else System.out.println("年龄合法");
    }

}
